package pkg.andru.widget;

import android.database.DataSetObservable;
import android.database.DataSetObserver;
import android.view.View;

/**
 * 
 * @author idiottiger
 * 
 */
public abstract class FlipPageAdapter<T> {

    private DataSetObservable mObservable = new DataSetObservable();

    /**
     * the create page callback
     * 
     * @param index
     *            the index in adpater
     * @return
     */
    public abstract View onCreatePage(int index);

    /**
     * when the view detroy callback
     * 
     * @param view
     *            the page destoryed view
     * @param index
     *            the index in adpater
     */
    public abstract void onDestroyPage(View view, int index);

    /**
     * get the pageitem with giving index
     * 
     * @param index
     * @return
     */
    public abstract T getPageItem(int index);

    /**
     * get the page label in giving index, can return null, default is return
     * null
     * 
     * @param index
     * @return
     */
    public String getPageLabel(int index) {
        return null;
    }

    /**
     * This method should be called by the application if the data backing this
     * adapter has changed and associated views should update.
     */
    public void notifyDataSetChanged() {
        mObservable.notifyChanged();
    }

    void registerDataSetObserver(DataSetObserver observer) {
        mObservable.registerObserver(observer);
    }

    void unregisterDataSetObserver(DataSetObserver observer) {
        mObservable.unregisterObserver(observer);
    }

}
